"""
数据库连接修改数据
"""
from pymysql import Connection

conn = None
cursor = None

try:
    conn = Connection(
        user="root",
        password="123456",
        host="localhost",
        port=3306,
        database="mydb1"
    )
    cursor = conn.cursor()
    sql = '''
        UPDATE hero SET h_name = "张宗航" WHERE h_name="李四";
    '''
    cursor.execute(sql)
    conn.commit()
except Exception as e:
    print(e)
finally:
    if conn:
        conn.close()
    if cursor:
        cursor.close()